#include "gui/objects/GUIRoute.h"

namespace gui {

GUIRoute::GUIRoute(GUIObjectDrawer* drawer, RouteController* routeController) : factory(drawer) {
	if (routeController != NULL) {
		// Se agregan los GUIRouteIntersection.
		util::LinkedList<MapPoint>::Iterator it = routeController->getRemainingIntersections();
		if (it.hasNext()) {
			// En este bloque se salva el caso en que no haya ruta, no se tendria que dibujar la unica interseccion.
			MapPoint first = *it.next();
			if (it.hasNext()) {
				this->addObjectToContainer(this->factory.createGUIRouteIntersection(first));
			}
		}
		while (it.hasNext()) {
			this->addObjectToContainer(this->factory.createGUIRouteIntersection(*it.next()));
		}
		// Se agregan los GUIRouteSegment y GUIRouteArrow.
		it = routeController->getRemainingIntersections();
		if (it.hasNext()) {
			MapPoint* previous = it.next();
			while (it.hasNext()) {
				MapPoint* current = it.next();
				this->addObjectToContainer(this->factory.createGUIRouteSegment(*previous, *current));
				this->addObjectToContainer(this->factory.createGUIRouteArrow(*previous, *current));
				previous = current;
			}
		}
	}
}

GUIRoute::~GUIRoute() {

}

}
